package com.tobeface.wechat.message.payload;

import com.tobeface.modules.lang.Requires;
import com.tobeface.wechat.message.WeChatMessageBuilder;
import com.tobeface.wechat.message.WeChatMessagePayloads;
import com.tobeface.wechat.message.WeChatMessageTypes;

import java.util.Map;

/**
 * @author loudyn
 */
public class LinkMessagePayloadBuilder extends AbstractMessagePayloadBuilder {

    private String title;
    private String descr;
    private String url;

    /**
     * @param parent
     */
    public LinkMessagePayloadBuilder(WeChatMessageBuilder parent) {
        super(parent);
    }

    /**
     * @param descr
     * @return
     */
    public LinkMessagePayloadBuilder descr(String descr) {
        Requires.hasText(descr, "Descr must not be empty or null!");
        this.descr = descr;
        return this;
    }

    /**
     * @param title
     * @return
     */
    public LinkMessagePayloadBuilder title(String title) {
        Requires.hasText(title, "Title must not be empty or null!");
        this.title = title;
        return this;
    }

    /**
     * @param url
     * @return
     */
    public LinkMessagePayloadBuilder url(String url) {
        Requires.hasText(url, "Url must not be empty or null!");
        this.url = url;
        return this;
    }

    @Override
    protected void configPayloads(Map<String, Object> payloads) {
        payloads.put(WeChatMessagePayloads.MSGTYPE_PAYLOAD, WeChatMessageTypes.LINK);
        payloads.put(WeChatMessagePayloads.TITLE_PAYLOAD, title);
        payloads.put(WeChatMessagePayloads.DESCR_PAYLOAD, descr);
        payloads.put(WeChatMessagePayloads.URL_PAYLOAD, url);
    }
}
